package com.siriuscloud.holidayreservation.utils;

import lombok.Data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

// 统一返回结果
@Data
public class R {
    private Integer code;
    private String msg;
    private Object data;

    private R() { }

    // 成功方法
    public static R ok() {
        R r = new  R();
        r.setCode(ResultCode.SUCCESS);
        r.setMsg("成功");
        return r;
    }

    // 失败方法
    public static R error() {
        R r = new  R();
        r.setCode(ResultCode.ERROR);
        r.setMsg("失败");
        return r;
    }

    public R data(Object data) {
        this.setData(data);
        return this;
    }

    public R dataEmptyArray() {
        this.setData(new ArrayList<>());
        return this;
    }

    public R dataEmptyMap() {
        this.setData(new HashMap<>());
        return this;
    }

    public R msg(String msg) {
        this.setMsg(msg);
        return this;
    }
}
